package ttsolver.constraints;

import ttsolver.input.Node;
import ttsolver.input.Train;

public class ConsFluxo extends DefaultConstraint {

	private Train train;
	private Node node;
	private int time;

	public ConsFluxo() {
		super(ConstraintType.CONS_FLOW);
	}

	public ConsFluxo(Train train, Node node, int time) {
		super(ConstraintType.CONS_FLOW);
		this.train = train;
		this.node = node;
		this.time = time;
	}

	public Train getTrain() {
		return train;
	}

	public void setTrain(Train train) {
		this.train = train;
	}

	public Node getNode() {
		return node;
	}

	public void setNode(Node node) {
		this.node = node;
	}

	public int getTime() {
		return time;
	}

	public void setTime(int time) {
		this.time = time;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((train == null) ? 0 : train.getId().intValue());
		result = prime * result
				+ ((node == null) ? 0 : node.getId().intValue());
		result = prime * result + time;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;

		ConsFluxo other = (ConsFluxo) obj;

		if (train == null) {
			if (other.train != null)
				return false;
		} else if (!train.equals(other.train)) {
			return false;
		}

		if (node == null) {
			if (other.node != null)
				return false;
		} else if (!node.equals(other.node)) {
			return false;
		}
		
		if (time != other.time) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		String s = "";
		s += (train != null) ? train.getId() : "N/A";
		s += (node != null) ? "," + node.getId() : "N/A";
		s += "," + time;
		return "Fluxo_(" + s + "):\n";
	}

}
